﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
using System.Globalization;

namespace Frontend
{
    [ValueConversion(typeof(String), typeof(Brush))]
    class EmptyStringToParameterConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter == null)
            {
                return null;
            }

            if (targetType != typeof(Brush))
            {
                throw new ArgumentException("Can convert only to Brush type");
            }            

            String str = value as String;

            if (str == null)
            {
                throw new ArgumentException("Value: converter supports only Strings as value types");
            }

            if (str.Length == 0)
            {
                return parameter;
            }
            else
            {
                return null;
            }
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
